<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加合同</title>
   <link href="css/contract.css" rel="stylesheet" type="text/css">
</head>
<body>
<!--header-->
<div class="top_box">
    <div id="" class="top">
        <div class="top_left">企业级视频直播解决方案</div>
        <div class="top_right"><a href="">关于我们&nbsp;&nbsp;</a>▏服务热线：400-048-2820</div>
        <div class="clearfix"></div>
    </div>

</div>
<div class="header_box">
    <div class="header">
        <div class="logo">
            <a href="#"><img src="images/logo.png"></a>

        </div>
        <ul class="tab_menu">

        </ul>
        <div class="clearfix"></div>
    </div>
</div>

<!--main-->
<div class="main">
    <div class="apply_box">
        <form  id="addForm" action="contractAdd" method="post">
            <ul class="form_ul">
                <li><label>甲方名称：</label><input type="text" name="firstPartyName" id="firstPartyName" value="" maxlength="20" placeholder="甲方名称"></li>
                <li><label>甲方地址：</label><input type="text" name="partyAddres" id="partyAddres" value="" placeholder="甲方地址" maxlength="50"></li>
                <li><label>甲方联系人：</label><input type="text" name="contacts" id="contacts"  value="" placeholder="甲方联系人" maxlength="4"></li>
                <li><label>联系人电话：</label><input type="text" name="telephone" id="telephone"  value="" onchange="telephoneOnchange()"  placeholder="甲方联系人手机号" maxlength="15"></li>
                <li><label>合同编号：</label><input type="text" name="contractNo" id="contractNo"   onchange="contractNoAmountChange()"   placeholder="合同编号"  maxlength="20"></li>
                <li><label>合同金额：</label><input type="text" name="contractAmount" id="contractAmount" onchange="contractAmountChange()"  value="" placeholder="合同金额(单位元)" maxlength="15"></li>

            	<div style="font-size: 13px;margin-bottom: 5px;">合同开始时间：<input type="text" name="startTime" id="startTime"  onclick="laydate()" class="laydate-icon">&nbsp;
            	 合同结束时间：<input type="text" name="endTime"   onclick="laydate()" id="endTime"  class="laydate-icon">
            	 </div>
            	<div style="font-size: 15px;margin-bottom: 5px;">
            	是否支付 : &nbsp;&nbsp;&nbsp;是<input name="whetherPay" type="radio"  value="1" checked="checked" />&nbsp;&nbsp;&nbsp;&nbsp; 
            								否<input name="whetherPay" type="radio" value="0" checked="checked"/></div>
            	<div style="font-size: 15px; margin-bottom: 5px;">销售人员：<select name="adminId" style="width: 180px;border:1px solid #999; margin-left: 0;height:30px;padding-left:9px;line-height:30px;">
						<option value="0" >请选择销售人员</option>
						     <c:forEach var="admin" items="${ requestScope.list}">
							<option value="${admin.id }" style="color: #000">${admin.name }</option>
						</c:forEach>
					</select>
					</div>           
				<li><label>备注：</label><input type="text" name="remarks" id="remarks"  value=""  placeholder="备注" maxlength="100"></li>
					     <li class="submit" style="border: none"><input type="button" onclick="submitContract();"  style="cursor:pointer" value="提交"><input type="button" onclick="history.go(-1)" style="cursor:pointer;margin-left: 20px;" value="返回"></li>
            </ul>
        </form>
    </div>
</div>
<!--foot-->
<div class="footer_box">
    <div class="footer">
        <p>Copyright@2016&nbsp;ZoomCloud&nbsp;众标科技,&nbsp; All&nbsp; right&nbsp; reserved.&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.miit.gov.cn" style="color: #8b97b1; text-decoration: none !important">皖ICP备16019558号</a> </p>
    </div>
</div>
</body>
<script src="js/jquery-1.7.2.js"></script>
<script src="js/jquery.tips.js"></script>
<script type="text/javascript" src="laydate/laydate.js"></script>
<script type="text/javascript">
var a = new Date();
var month = a.getMonth()+1;
if(month<10){
	month = "0" +month;
}
var day = a.getDate();
if(day<10){
	day = "0" + day;
}
$("#startTime").val(a.getFullYear()+"-"+month+"-"+day);
$("#endTime").val(a.getFullYear()+"-"+month+"-"+day);

function telephoneOnchange(){
    var inp= document.getElementById("telephone");
    var reg=/^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
    var result= reg.test(inp.value);
    if(!result)
    {
 	   $("#telephone").tips({
				side : 1,
				msg : '请输入正确的手机号码',
				bg : '#AE81FF',
				time : 3
			});
 	  return false;
    }
   }
function contractNoAmountChange(){
    var inp= document.getElementById("contractNo");
    var reg = /^[A-Za-z0-9]+$/;
    var result= reg.test(inp.value);
    if(!result)
    {
 	   $("#contractNo").tips({
				side : 1,
				msg : '只能输入字母和数字',
				bg : '#AE81FF',
				time : 3
			});
 	  return false;
    }
    var contractNo = $("input[name='contractNo']").val();
   $.ajax({
    	type: "POST",
		url: 'checkContactNo',
    	data: {contractNo :contractNo },
    	dataType: "html",
		cache: false,
		success: function(data) {
			if(data==1){
				$("#contractNo").tips({
					side : 1,
					msg : '合同编号已存在',
					bg : '#AE81FF',
					time : 5
				});
				$("#contractNo").focus();
				return false;
			}
		}
	}); 
   }
function contractAmountChange() {
	var inp = document.getElementById("contractAmount");
	var reg = /^[0-9]+$/;
	var result = reg.test(inp.value);
	if (!result) {
		$("#contractAmount").tips({
			side : 1,
			msg : '请输入数字',
			bg : '#AE81FF',
			time : 3
		});
		return false;
	}
}
function submitContract(){
			var firstPartyName = $("input[name='firstPartyName']").val();
			var partyAddres = $("input[name='partyAddres']").val();
			var contacts = $("input[name='contacts']").val();
			var telephone = $("input[name='telephone']").val();
			var contractNo = $("input[name='contractNo']").val();
			var contractAmount = $("input[name='contractAmount']").val();
			if (firstPartyName == "") {
					$("#firstPartyName").tips({
						side : 1,
						msg : '甲方名称不得为空',
						bg : '#AE81FF',
						time : 3
					});

					$("#firstPartyName").focus();
					return false;
				}
				if (partyAddres == "") {
					$("#partyAddres").tips({
						side : 1,
						msg : '甲方地址不得为空',
						bg : '#AE81FF',
						time : 3
					});

					$("#partyAddres").focus();
					return false;
				}
				
				if (contacts == "") {
					$("#contacts").tips({
						side : 1,
						msg : '甲方联系人不得为空',
						bg : '#AE81FF',
						time : 3
					});

					$("#contacts").focus();
					return false;
				}
				
				if (telephone == "") {
					$("#telephone").tips({
						side : 1,
						msg : '甲方联系人手机号不得为空',
						bg : '#AE81FF',
						time : 3
					});

					$("#telephone").focus();
					return false;
				}
				if (contractNo == "") {
					$("#contractNo").tips({
						side : 1,
						msg : '合同编号不得为空',
						bg : '#AE81FF',
						time : 3
					});
					$("#contractNo").focus();
					return false;
					}
				if (contractAmount == "") {
					$("#contractAmount").tips({
						side : 1,
						msg : '合同金额不得为空',
						bg : '#AE81FF',
						time : 3
					});

					$("#contractAmount").focus();
					return false;
				}
				if($("#startTime").val()==''){
					$("#startTime").tips({
						side : 1,
						msg : '	请选择合同开始时间',
						bg : '#0099FF',
						time : 3
					});
					return false;
				}
				if($("#endTime").val()==''){
					$("#endTime").tips({
						side : 1,
						msg : '	请选择合同结束时间',
						bg : '#0099FF',
						time : 3
					});
					return false;
				}
				 var e = $.trim($("#startTime").val());
				 var f = $.trim($("#endTime").val());
				    if(e>f){
				    	$("#endTime").tips({
							side : 1,
							msg : '合同开始时间要迟于合同结束时间',
							bg : '#0099FF',
							time : 3
						});
				    	 return false;
				    }
				    var reg1=/^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
				    var result1= reg1.test(telephone);
				    if(!result1)
				    {
				 	   $("#telephone").tips({
								side : 1,
								msg : '请输入正确的手机号码',
								bg : '#AE81FF',
								time : 3
							});
				 	  return false;
				    }
				    var reg2 = /^[A-Za-z0-9]+$/;
				    var result2= reg2.test(contractNo);
				    if(!result2)
				    {
				 	   $("#contractNo").tips({
								side : 1,
								msg : '只能输入字母和数字',
								bg : '#AE81FF',
								time : 3
							});
				 	  return false;
				    }
					var reg3 = /^[0-9]+$/;
					var result3 = reg3.test(contractAmount);
					if (!result3) {
						$("#contractAmount").tips({
							side : 1,
							msg : '请输入数字',
							bg : '#AE81FF',
							time : 3
						});
						return false;
					}
					 $.ajax({
					    	type: "POST",
							url: 'checkContactNo',
					    	data: {contractNo :contractNo },
					    	dataType: "html",
							cache: false,
							success: function(data) {
								if(data==1){
									$("#contractNo").tips({
										side : 1,
										msg : '合同编号已存在',
										bg : '#AE81FF',
										time : 5
									});
									$("#contractNo").focus();
									return false;
								}
								$("#addForm").submit();
								}
						});
				}
				
				</script>
</html>